///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_APP_CAPP_H_
#define _BUOLA_APP_CAPP_H_

#include <buola/buola.h>

namespace buola {

///\addtogroup application
///@{

////////////////////////////////////////////////////////////////////////////

/// application object

/// This is the entry point for all buola applications. It contains a Main
/// function, which should be called from int main(), and is responsible
/// for parsing command-line parameters and creating the main loop.
///
/// For applications that don't use the main loop for all flow control, it
/// is also possible to call Init and DeInit manually.
///
/// To define custom startup and cleanup behavior, there are some functions
/// that it is possible to override, and they will be called during
/// initialization and termination.
///
/// The cycle of an application is as follows:
/// - Start() is called
/// - the main loop runs
/// - Finish() is called
///
////////////////////////////////////////////////////////////////////////////

class CApp : public UUncopiable
{
public:
//! \name constructor and destructor
//@{
    CApp();
    virtual ~CApp();
//@}

public:
//! \name application start-up
//@{
    //! run the application

    //! Should only be called from int main().
    //! It initializes the application and runs the main loop until a signal
    //! or exception is caught or the program is normally terminated.
    void Run();
//@}

protected:
//! \name startup and cleanup
//@{
    //!things to be done just before entering the main loop
    virtual bool Start()		{	return true;	}
    //!things to be done just after exiting the main loop
    virtual void Finish() {}
//@}

public:
    virtual std::string GetApplicationName()    {   return "buola"; }

//! \name persistence
//! \todo implement this
//@{
    virtual void OnSaveState(const xml::CNode&) {}
    virtual void OnRestoreState(const xml::CNode&) {}
//@}
};

///returns the main application object
CApp *get_application_object();

///@}

/*namespace buola*/ }

#endif
